package com.itheima.sh.sk.test;

import com.itheima.sh.sk.dao.UserMapper;
import com.itheima.sh.sk.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class Demo02 {
    public static void main(String[] args) throws IOException {

        // 创建会话工厂创造类对象
        SqlSessionFactoryBuilder factoryBuilder = new SqlSessionFactoryBuilder();
        // 获取会话工厂类对象
        // 使用类加载器关联核心配置文件
        InputStream inputStream = Resources.getResourceAsStream("mybatis.xml");
        SqlSessionFactory factory = factoryBuilder.build(inputStream);

        // 获取会话对象
        SqlSession sqlSession = factory.openSession();
        // 使用会话对象sqlSession调用方法获取接口UserMapper代理对象
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        // 使用接口的代理对象调用接口中得查询所有用户方法
        List<User> list = mapper.queryAllUsers();

//        list.forEach(System.out::println);

    }
}
